class Solution {
    /**
        滑动窗口
    */
    public int minSubArrayLen(int target, int[] nums) {
        int left=0, right=-1;
        int sum = 0;
        int len = nums.length;
        int ans = Integer.MAX_VALUE;
        while (left < len){
            // 滑动窗口右移
            while (right+1 <= len-1 && sum < target){
                right ++;
                sum += nums[right];
            }
            if( sum>=target ){
                ans = Math.min(ans,right-left+1);
            }
            // 滑动窗口左移
            sum -= nums[left];
            left++;
        }
        return ans == Integer.MAX_VALUE ? 0 : ans;
    }
}